<?xml version="1.0" encoding="UTF-8"?>
<!--
To change this template, choose Tools | Templates
and open the template in the editor.
-->
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml"
      xmlns:f="http://java.sun.com/jsf/core"
      xmlns:ui="http://java.sun.com/jsf/facelets"
      xmlns:h="http://java.sun.com/jsf/html"
      xmlns:p="http://primefaces.prime.com.tr/ui">
    <ui:composition template="/view/template.xhtml">
        <ui:define name="head">
            <script type="text/javascript">
              function handleConfirmRequest(xhr, status, args) {
                      if(args.success) {
                              postingDialog.hide();
                      }
              }

                function handleSettlementRequest(xhr, status, args){
                       if(args.success) {
                              postingDialog.show();
                      }
               }
            </script>
        </ui:define>
        <ui:define name="content">
            <f:view>
                <h:form id ="form1">
                    <p:dataTable value="#{financeManager.formList}" var="item" id="forms" paginator="true" rows="20">
                        <f:facet name="header">
                            <h:panelGrid columns="2" cellpadding="0" cellspacing="0">
                                <p:breadCrumb preview="true" expandEffectDuration="200" previewWidth="20" style="width: 500px" expandedBeginningItems="1" expandedEndItems="0">
                                    <p:menuitem value="选项"/>
                                    <p:menuitem value="查询未完成结算单" actionListener="#{financeManager.findUnSettledForm}" update="form1:forms"/>
                                </p:breadCrumb>
                                <h:panelGrid columns="6" style="width: 400px">
                                    <h:selectOneMenu value="#{financeManager.formType}">
                                        <f:selectItems value="#{applicationBean.formTypeSelectList}"></f:selectItems>
                                        <p:ajax  update="form1:forms" listener="#{financeManager.searchByType}" />
                                    </h:selectOneMenu>

                                    <h:outputLabel value="模糊查询"></h:outputLabel>
                                    <h:inputText value="#{financeManager.formNumber}" title="可输入部分单号进行查询"></h:inputText>

                                    <p:commandLink update="form1:forms" actionListener="#{financeManager.search}" title="查询">
                                        <p:graphicImage value="/resources/images/search.png"/>
                                    </p:commandLink>
                                    <p:ajaxStatus  style="width:16px;height:16px;">
                                        <f:facet name="start">
                                            <h:graphicImage  value="/resources/images/ajaxloading.gif" />
                                        </f:facet>
                                        <f:facet name="complete">
                                            <h:outputText value=""/>
                                        </f:facet>
                                    </p:ajaxStatus>
                                </h:panelGrid>
                            </h:panelGrid>
                        </f:facet>


                        <p:column>
                            <f:facet name="header">
                                <h:outputText value="单号:"/>
                            </f:facet>
                            <h:outputText value="#{item.number}"/>
                        </p:column>
                        <p:column>
                            <f:facet name="header">
                                <h:outputText value="创建时间:"/>
                            </f:facet>
                            <h:outputText value="#{item.createdTime}">
                                <f:convertDateTime pattern="MM/dd/yyyy HH:mm:ss" />
                            </h:outputText>
                        </p:column>

                        <p:column>
                            <f:facet name="header">
                                <h:outputText value="类型:"/>
                            </f:facet>
                            <h:outputText value="#{item.type}"/>
                        </p:column>

                        <p:column>
                            <f:facet name="header">
                                <h:outputText value="创建人"/>
                            </f:facet>
                            <h:outputText value="#{item.createdBy.name}"/>
                        </p:column>
                        <p:column>
                            <f:facet name="header">
                                <h:outputText value="结算单信息"/>
                            </f:facet>
                            <h:outputText value="#{item.formInfo}"/>
                        </p:column>
                        <p:column headerText="选项">
                            <h:panelGrid columns="3">
                                <p:commandLink title="收款" action="#{financeManager.receive(item,'收入')}" oncomplete="handleSettlementRequest(xhr, status, args)" update="form3:posting,form:growl" >
                                    <p:graphicImage value="/resources/images/download.gif"/>
                                </p:commandLink>
                                <p:commandLink title="付款" action="#{financeManager.pay(item,'支出')}" oncomplete="handleSettlementRequest(xhr, status, args)" update="form3:posting,form:growl" >
                                    <p:graphicImage value="/resources/images/upload.png"/>
                                </p:commandLink>
                                <p:commandLink title="查看历史记录" action="#{financeManager.select(item)}" oncomplete="formDialog.show()" update="form2:display,form2:postings" >
                                    <p:graphicImage value="/resources/images/search.png"/>
                                </p:commandLink>
                            </h:panelGrid>
                        </p:column>
                    </p:dataTable>
                </h:form>


                <p:dialog widgetVar="formDialog" modal="true" width="500" header="结算记录">
                    <h:form id="form2">
                        <h:panelGrid columns="2" id ="display">
                            <h:outputLabel value="单号:"  />
                            <h:outputLabel  value="#{financeManager.form.number}" title="number" />
                            <h:outputLabel value="类别:" />
                            <h:outputLabel  value="#{financeManager.form.type}" title="name" />
                            <h:outputLabel value="是否结单:"  />
                            <h:selectBooleanCheckbox value="#{financeManager.form.settled}" disabled="true"/>
                            <h:outputLabel value="是否取消:"  />
                            <h:selectBooleanCheckbox value="#{financeManager.form.cancelled}" disabled="true"/>
                            <h:outputLabel value="结算单信息: "/>
                            <h:outputText value="#{financeManager.form.formInfo}"/>
                        </h:panelGrid>

                        <p:dataTable id="postings" value="#{financeManager.form.postingCollection}" var="posting">
                            <p:column>
                                <f:facet name="header">
                                    <h:outputText value="付款方式"/>
                                </f:facet>
                                <h:outputText value="#{posting.paymentMethod}"/>
                            </p:column>
                            <p:column>
                                <f:facet name="header">
                                    <h:outputText value="金额"/>
                                </f:facet>
                                <h:outputText value="#{posting.amount}"/>
                            </p:column>
                            <p:column>
                                <f:facet name="header">
                                    <h:outputText value="时间"/>
                                </f:facet>
                                <h:outputText value="#{posting.createdTime}">
                                    <f:convertDateTime pattern="yyyy-MM-dd" timeZone="#{applicationBean.timeZone}"/>
                                </h:outputText>
                            </p:column>
                            <p:column>
                                <f:facet name="header">
                                    <h:outputText value="创建人"/>
                                </f:facet>
                                <h:outputText value="#{posting.createdBy.name}"/>
                            </p:column>
                            <p:column>
                                <f:facet name="header">
                                    <h:outputText value="经手人"/>
                                </f:facet>
                                <h:outputText value="#{posting.handler.name}"/>
                            </p:column>
                            <p:column>
                                <f:facet name="header">
                                    <h:outputText value="类别"/>
                                </f:facet>
                                <h:outputText value="#{posting.type}"/>
                            </p:column>
                        </p:dataTable>
                    </h:form>
                </p:dialog>

                <p:dialog widgetVar="postingDialog" modal="true" width="300" header="结算">
                    <h:form id="form3">
                        <h:panelGrid columns="2" id ="posting">
                            <h:outputLabel value="单号:"  />
                            <h:outputLabel  value="#{financeManager.posting.form.number}" title="number" />
                            <h:outputLabel value="结算单类别:" />
                            <h:outputLabel  value="#{financeManager.posting.form.type}"  />
                            <h:outputLabel value="已结单:"  />
                            <h:selectBooleanCheckbox value="#{financeManager.posting.form.settled}" disabled="true"/>
                            <h:outputLabel value="已取消:"  />
                            <h:selectBooleanCheckbox value="#{financeManager.posting.form.cancelled}" disabled="true"/>
                            <h:outputLabel value="结算单明细:" />
                            <h:inputTextarea  value="#{financeManager.posting.form.formInfo}" disabled="true"/>
                            <h:outputLabel value="结算类型:" />
                            <h:outputLabel  value="#{financeManager.posting.type}"  />
                            <h:outputLabel value="付款方式:" />
                            <h:selectOneMenu  value="#{financeManager.posting.paymentMethod}" required="true" requiredMessage="请选择付款方式">
                                <f:selectItems value="#{applicationBean.paymentMethodSelectItems}" />
                            </h:selectOneMenu>
                            <h:outputLabel value="经手人:" />
                            <h:selectOneMenu  value="#{financeManager.posting.handler}">
                                <f:selectItems value="#{applicationBean.employeeSelectItems}"/>
                            </h:selectOneMenu>
                            <h:outputLabel value="金额:"  />
                            <h:inputText value="#{financeManager.posting.amount}" validatorMessage="金额必须大于0">
                                <f:validateDoubleRange minimum="0"></f:validateDoubleRange>
                            </h:inputText>
                            <f:facet name="footer">
                                <h:panelGroup>
                                    <p:commandButton  value="确认" actionListener="#{financeManager.confirmSettlement}"  update="form1:forms,form:growl" oncomplete="handleConfirmRequest(xhr, status, args)"></p:commandButton>
                                </h:panelGroup>
                            </f:facet>
                        </h:panelGrid>
                    </h:form>
                </p:dialog>
            </f:view>
        </ui:define>
    </ui:composition>
</html>
